;
(function() {
	var skill = {
		getBusUser_List: function(num, page) {
			var list = BusUserCon.findByUserId(this._id);
			list = data_cut.page(list, num, page);
			list = list.map(function(bus_user) {
				bus_user = $Object.clone(bus_user);
				bus_user.bus = BusCon.get(bus_user.bus_id);
				return bus_user;
			});
			return list;
		},
		getBusUser_by_busId: function(bus_id) {
			var bus_user = BusUserCon.get(BusUserCon.build({
				bus_id: bus_id,
				user_id: this._id
			}));
			return bus_user;
		},
		bus_user_state_未申请兑换_to_申请兑换中: function(bus_id, money_apply) {
			var bus_user = BusUserCon.get(BusUserCon.build({
				bus_id: bus_id,
				user_id: this._id
			}));
			console.log("bus_user.state", bus_user.state);
			if (!bus_user.money) {
				throwCusError("无可兑换的红利")
			}
			if (!bus_user.state) {
				bus_user.state = BusUserCon.STATE.未申请兑换;
			}
			if (bus_user.state == BusUserCon.STATE.未申请兑换) {
				bus_user._applyMoney(money_apply);
				bus_user._nextFlowStatus();
			} else {
				throwCusError("兑现所在状态无法进行相应转换");
			}
			bus_user = $Object.clone(bus_user);

			bus_user.bus = BusCon.get(bus_user.bus_id);

			return bus_user;
		},
		bus_user_state_申请兑换中_to_未申请兑换: function(bus_id) {
			var bus_user = BusUserCon.get(BusUserCon.build({
				bus_id: bus_id,
				user_id: this._id
			}));

			if (bus_user.state !== BusUserCon.STATE.申请兑换中) {
				throwCusError("兑现所在状态无法进行相应转换")
			}
			console.log("bus_user.state", bus_user.state);

			bus_user.state = BusUserCon.STATE.未申请兑换;
			bus_user._cancelApplyMoney();

			bus_user = $Object.clone(bus_user);

			bus_user.bus = BusCon.get(bus_user.bus_id);

			return bus_user;
		},
		bus_user_state_商家已经打款_to_用户确认收款: function(bus_id) {
			var bus_user = BusUserCon.get(BusUserCon.build({
				bus_id: bus_id,
				user_id: this._id
			}));
			if (!bus_user.state) {
				bus_user.state = BusUserCon.STATE.未申请兑换;
			}
			if (bus_user.state == BusUserCon.STATE.商家已经打款) {
				// bus_user._nextFlowStatus();
				bus_user.state = BusUserCon.STATE.未申请兑换;
				bus_user._confirmApplyMoney();
			} else {
				throwCusError("兑现所在状态无法进行相应转换");
			}
			bus_user = $Object.clone(bus_user);

			bus_user.bus = BusCon.get(bus_user.bus_id);

			return bus_user;
		},
		bindBusUserMoneyToAch: function(ach_id, money) {
			var ach = this._getAch(ach_id);
			return ach._bindBusUserMoney(money);
		}
	};
	module.exports = skill;
	var db = require("../db/index");
	var CouponCon = require("../coupon/_con");
	var DomainCon = require("../domain/_con");
	var GoodsCon = require("../goods/_con");
	var UserCon = require("../../core/user/_con");
	var BusCon = require("../../core/bus/_con");
	var AchCon = require("../ach/_con");
	var ClassifyCon = require("../bus.classify/_con");
	var TagCon = require("../bus.tag/_con");
	var LeagueCon = require("../league/_con");
	var BuffCon = require("../buff/_con");
	var BusUserCon = require("../bus_user/_con");
	var BusUserBindCon = require("../bus_user/_con");
	var BusGuideCon = require("../bus.guide/_con");
	var CommentCon = require("../comment/_con");
	var config = require("../_include/config");
	var data_cut = require("../_include/data_cut");
	var helper = require("../_include/helper");
	var md5 = require("../_include/md5");
	var $Object = require("../_include/$.Object");
	var $Array = require("../_include/$.Array");
	var tld = require('tldjs');
	var fs = require("fs");
	var Fiber = require('fibers');
}());